# coding:utf8
import findspark

findspark.init()
from pyspark import SparkConf, SparkContext

if __name__ == '__main__':
    conf = SparkConf().setAppName("test").setMaster("local[*]")
    sc = SparkContext(conf=conf)
    rdd = sc.parallelize([1, 2, 3, 4, 5, 6])
    # 将数字按照奇数和偶数分组求和
    rdd1 = rdd.groupBy(lambda x: 'even' if (x % 2 == 0) else 'odd')
    print(rdd1.map(lambda x: (x[0], sum(list(x[1])))).collect())
